//
//  TTNavViewController.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/4.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit

class TTNavViewController: UINavigationController ,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

    self.interactivePopGestureRecognizer?.delegate = self
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count > 0 {
        
        if viewControllers.count == 1 {
            
        let title2 = viewControllers.first?.title
           viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title1:title2! , target: self, action: #selector(popVc), imageName: "navigationbar_back_withtext")
        
        }else
        {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title1: "返回", target: self, action: #selector(popVc), imageName: "navigationbar_back_withtext")
     
        }
        
            viewController.hidesBottomBarWhenPushed = true
            
            viewController.title = "当前是第\(viewControllers.count + 1)个控制器"
        }
        
        
       
        super.pushViewController(viewController, animated: animated)
        
        
    }
 
 @objc private func popVc()
  {
      self .popViewController(animated: true)
    
 }
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if viewControllers.count == 1
        {
        return false
        }
        return true
    }
    
}
